﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FaultBackService.Models;

namespace FaultBackService.DAL
{
    class TrendStableValue
    {
        /// <summary>
        /// 获取趋势分析最新记录
        /// </summary>
        /// <returns></returns>
        internal Models.TrendStableValue GetLastOne()
        {
            using (Models.TurbineFaultContext context=new Models.TurbineFaultContext())
            {
                return context.TrendStableValue
                    .OrderByDescending(e => e.Id)
                    .FirstOrDefault();
            }
        }

        /// <summary>
        /// 向表TrendStableValue中插入一条新记录
        /// </summary>
        /// <param name="value"></param>
        internal void Add(Models.TrendStableValue value)
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                context.TrendStableValue.Add(value);
                context.SaveChanges();
            }
        }

        /// <summary>
        /// 向TrendStableValue中写入多条数据
        /// </summary>
        /// <param name="list"></param>
        internal int AddRange(IList<Models.TrendStableValue> list)
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                context.TrendStableValue.AddRange(list);
                return context.SaveChanges();
            }
        }
    }
}
